// 用户名
let username = document.getElementById('username')
let usermsg = document.getElementById('usermsg')
// 手机
let userphone = document.getElementById('userphone')
let phonemsg = document.getElementById('phonemsg')
// 密码
let userpass = document.getElementById('userpass')
let passmsg = document.getElementById('passmsg')
// 登录
let btnreg = document.getElementById('btnreg')
let btn = document.getElementById('btn')

function loginCheck() {
    // 1.非空判断
    if (username.value === '' && userphone.value === '' && userpass.value === '') {
        btn.innerHTML = '用户名、手机号、密码不能为空'
        btn.style.color = 'red'
        btn.style.fontSize = '12px'
        return false
    }

    ajaxUsePromise02({
        url: 'http://localhost:3000/vips',
        method: 'get',
        data: `username=${$("#username").val()}&userphone=${$("#userphone").val()}&userpass=${$("#userpass").val()}`
    }).then(res => {
        if (res.length != 0) {
            console.log("非空", res);
            res.forEach(element => {
                saveCookie("userid", element.id, 7);
                saveCookie("username", element.username, 7);
                saveCookie("userphone", element.userphone, 7);
                saveCookie("userpass", element.userpass, 7);
                saveCookie("userpass2", element.userpass2, 7);
            });
            location.href = "./index.html"
        } else if (res.length == 0) {
            $("#btn").html("库中没有该用户").css({ color: "red" });
            console.log("空", res);

        }
    })

}


window.onload = function () {
    $('#btnreg').on('click', loginCheck)
}